<?php

namespace system\components;

/**
 * {@link DocumentComponent} element that agregates exception related info.
 *
 * This Component holds all nacessary information about
 * exception so that information may be represented visually
 * using XSL template.
 *
 * XML representation:
 * 	 <code>
 * 	 		<Exception>
 *                              <message></message>
 * 	 			<type></type>
 * 	 			<file></file>
 * 	 			<line></line>
 * 	 			<stacktrace>
 *                                  <traceline><traceline>
 *                              </stacktrace>
 * 	 		</Exception>
 * 	 </code>
 *
 * @see DocumentComponent,Exception
 * @package system\components
 * @author Pavel Egorov {@link mailto:pavel@egorov.ru pavel@egorov.ru}
 * @version 0.0.1 $Revision: 61 $
 * @copyright Copyright (c) 2011, Pavel Egorov
 */
class ExceptionComponent extends DocumentComponent {

    /**
     * Name(name of the class) of exeption throwed
     * @var String
     */
    public $type;

    /**
     * Creates an instance of {@link ExceptionComponent} and initialize component parameters
     * @param $exception {@link Exception}
     */
    function __construct(\Exception $exception) {
        parent::__construct("exception");
        $this->message = $exception->getMessage();
        $this->type = preg_replace('#^.*\\\(.+)$#', '$1',get_class($exception));
        $this->file = $exception->getFile();
        $this->line = $exception->getLine();
        foreach($exception->getTrace() as $line){
            $this->stackTrace[] = new ExceptionTraceLineComponent($line);
        }
    }

}